package van.planifolia.work;

import java.util.concurrent.*;

/**
 * Created by Intellij IDEA<br>
 *
 * @author Planifolia.Van
 * @version 1.0
 * @date 2022/11/2 16:01
 */
public class ManyThreadPool {
    public static void main(String[] args) {
        // 创建定长线程池
//        ExecutorService executorService = Executors.newFixedThreadPool(3);
        // 创建单个线程执行器
//        ExecutorService executorService = Executors.newSingleThreadExecutor();
        // 创建缓冲线程池
        ExecutorService executorService = Executors.newCachedThreadPool();
        // 创建延迟线程池
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(3);
        for (int i = 0; i < 5; i++) {
            scheduledExecutorService.schedule(()->{
                System.out.println(Thread.currentThread().getName() + "：你好");
            },5000, TimeUnit.MILLISECONDS);
        }
        // 使用这个线程池执行十个任务
        for (int i = 0; i < 26; i++) {
            executorService.submit(()->{
                System.out.println(Thread.currentThread().getName() + "：你好");
            });
        }
    }
}
